package io.github.qifan777.knowledge.ai.agent.db;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import io.github.qifan777.knowledge.ai.agent.AbstractAgent;
import io.github.qifan777.knowledge.ai.agent.Agent;
import io.github.qifan777.knowledge.ai.agent.chronologist.Chronologist;
import io.github.qifan777.knowledge.service.impl.UserService;
import lombok.AllArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.context.annotation.Description;

import java.util.function.Function;

/**
 * @author tjw
 * @date 2025-04-22
 * @Description
 */

@Agent
@Description("操作数据库")
@AllArgsConstructor
public class DbOpertionAssistant extends AbstractAgent implements Function<DbOpertionAssistant.Request, String> {


    private final String SYSTEM = """
            操作数据库
            """;

    private final ChatModel chatModel;

    @Override
    public String apply(DbOpertionAssistant.Request request) {
                // 调用模型
        return ChatClient.create(chatModel)
                .prompt()
                //
                .system(SYSTEM)
                //用户提示词
                .user(request.query)
                // 带有@bean的方法
                .functions("getUserDetails")
                // call代表非流式问答，返回的结果可以是ChatResponse，也可以是Entity（转成java类型），也可以是字符串直接提取回答结果
                .call()
                .content();
    }

    public record Request(@JsonProperty(required = true) @JsonPropertyDescription("用户原始的提问") String query) {
    }
}
